package net.xdclass.online_xdclass.utils;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.boot.autoconfigure.jms.JmsProperties;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class BaseCache {

    private Cache<String,Object> tenMinuteCache= CacheBuilder.newBuilder()
//            设置缓存初始大小，应该合理设置，后续会扩容
            .initialCapacity(10)
//            最大值
            .maximumSize(100)
//            并发数设置
            .concurrencyLevel(5)
//            缓存过期时间写入后10分钟过期
            .expireAfterAccess(600, TimeUnit.SECONDS)
//            统计缓存命中率
            .recordStats()

            .build();

    public Cache<String, Object> getOneMinuteCache() {
        return oneMinuteCache;
    }

    public void setOneMinuteCache(Cache<String, Object> oneMinuteCache) {
        this.oneMinuteCache = oneMinuteCache;
    }

    private Cache<String,Object> oneMinuteCache= CacheBuilder.newBuilder()
//            设置缓存初始大小，应该合理设置，后续会扩容
            .initialCapacity(10)
//            最大值
            .maximumSize(100)
//            并发数设置
            .concurrencyLevel(5)
//            缓存过期时间写入后10分钟过期
            .expireAfterAccess(3600, TimeUnit.SECONDS)
//            统计缓存命中率
            .recordStats()

            .build();

    public Cache<String, Object> getTenMinuteCache() {
        return tenMinuteCache;
    }

    public void setTenMinuteCache(Cache<String, Object> tenMinuteCache) {
        this.tenMinuteCache = tenMinuteCache;
    }


}
